import lookup from "./lookup"

export default function renderTemplate(tokens, data) {
  let resultStr = ''

  for (let i = 0; i < tokens.length; i++) {
    let token = tokens[i]
    if (token[0] == 'text') {
      resultStr += token[1]
    } else if (token[0] == 'name') {
      resultStr += lookup(data,token[1])
    } else if(token[0] == '#'){

      let v = lookup(data,token[1])

      for(let j = 0; j < v.length; j++){
        resultStr += renderTemplate(token[2],{
          '.': v[j],
          ...v[j]
        })
      }

    } 
  }
  
  return resultStr
}